<?php
require_once "../global.php";
session_start();
check_pass();
baca_permisi(4);
global $permisi;
global $mode,$DisBuku,$Ddivisi,$DisBayar,$DisLapor,$DLWilayah,$DNoFak,$idrek;
if($permisi["access"]=="tolak"){
	header('Location:../tengah.php');
}
?>
<html>
<head>
<title>Data Master</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../css/style.css" rel="stylesheet" type="text/css" />
</head>
<body leftmargin="0" topmargin="0">
<?php

if ($mode==''){
    $condLoc = "";
}else{
    $condLoc = " AND a.no_faktur_pajak='$DNoFak' AND a.id_leveransir='$idrek'";
}
if ($DLWilayah=="KP"){
    $DdivisiS = explode(".",$Ddivisi);
    $DdivisiLength = strlen($DdivisiS[0]);
    $condWil .=" substr(a.divisi_kode,1,$DdivisiLength)='$Ddivisi'";
}else{
    $condWil .=" a.divisi_kode='$Ddivisi'";
}

if ($DisBuku=="Y"){
    $cont .=" AND a.is_buku='Y'";
}else if($DisBuku=="N"){
    $cont .=" AND a.is_buku='N'";
}else{
    $cont .="";
}
if ($DisBayar=="Y"){
    $cont .=" AND a.is_bayar='Y'";
}else if($DisBayar=="N"){
    $cont .=" AND a.is_bayar='N'";
}else{
    $cont .="";
}
if ($DisLapor=="Y"){
    $cont .=" AND a.is_lapor='Y'";
}else if($DisLapor=="N"){
    $cont .=" AND a.is_lapor='N'";
}else{
    $cont .="";
}

// Validasi Akses Divisi
if ($Ddivisi=='KP'){
    $cond_divisi_kode = "WHERE $condWil $cont $condLoc";
}else{
    $cond_divisi_kode = "WHERE $condWil $cont $condLoc";
}
// END Validasi Akses Divisi

// field seacrh
//$SQL = "select a.*,b.divisi_name,c.nama_leveransir,c.npwp_leveransir,c.alamat_leveransir,d.nama_proyek from tbl_spt a
//        JOIN tbl_divisi b ON (a.divisi_kode = b.divisi_kode)
//        JOIN m_leveransir c ON (a.id_leveransir = c.id_leveransir)
//        JOIN m_proyek d ON (a.id_proyek = d.id_proyek) $cond_divisi_kode";
//$SQLcari = "select a.no_faktur_pajak,c.nama_leveransir,c.npwp_leveransir,a.bukti_pencatatan,d.nama_proyek,b.divisi_name from tbl_spt a
//            JOIN tbl_divisi b ON (a.divisi_kode = b.divisi_kode)
//            JOIN m_leveransir c ON (a.id_leveransir = c.id_leveransir)
//            JOIN m_proyek d ON (a.id_proyek = d.id_proyek) $cond_divisi_kode";
//$search = $_POST['txtSearch'];
//
//$sqlq = getRSq($SQLcari);
//$jmlField = pg_num_fields($sqlq);
//for ($x=0;$x<$jmlField;$x++){
//    $namaField = pg_field_name($sqlq, $x);
//    $cond .= "lower(CAST(".$namaField." as TEXT)) LIKE lower('%$search%') OR ";
//}
//$condition = substr($cond,0,strlen($cond)-3);
// end field search
if(isset($_POST['tbSearch'])){
    // TANGGAL CARI
        $kata=strtolower(trim($_POST['txtSearch']));
	if($kata<>""){
		$SQLtambahan = " and (lower(a.no_faktur_pajak) like('%".$kata."%'))";
	}

        $tgl1 = $_POST['tglCari1'];
        $bln1 = $_POST['blnCari1'];
        $thn1 = $_POST['thnCari1'];

        $tgl2 = $_POST['tglCari2'];
        $bln2 = $_POST['blnCari2'];
        $thn2 = $_POST['thnCari2'];
        // get Total hari/bulan
        $_POST['tglCari1'] = e_getTotalDay($_POST['thnCari1'], $_POST['blnCari1'], $_POST['tglCari1']);
        $_POST['tglCari2'] = e_getTotalDay($_POST['thnCari2'], $_POST['blnCari2'], $_POST['tglCari2']);
	$tgl_awal=mktime(0,0,0,$_POST['blnCari1'],$_POST['tglCari1'],$_POST['thnCari1']);
	$tgl_akhir=mktime(0,0,0,$_POST['blnCari2'],$_POST['tglCari2'],$_POST['thnCari2']);
	$tglcari1=date("Y-m-j",$tgl_awal);
	$tglcari2=date("Y-m-j",$tgl_akhir);
     // END TANGGAL CARI
         $SQLtambahan .= " AND (a.tgl_faktur>='$tglcari1' AND a.tgl_faktur<='$tglcari2')";
 }else{
        $tgl1 = "1";
        $bln1 = "01";
        $thn1 = "2004";
        $tglcari1 = "$thn1-$bln1-$tgl1";
        $tgl2 = date("j");
        $bln2 = date("m");
        $thn2 = date("Y");
        $tglcari2 = "$thn2-$bln2-$tgl2";
        $SQLtambahan .= " AND (a.tgl_faktur>='$tglcari1' AND a.tgl_faktur<='$tglcari2')";
 }
?>
<table width="98%" height="auto" border="0" align="center" cellpadding="0" cellspacing="0">
 <tr>
    <td height="30" valign="top" colspan="2">
      <table width="98%" height="35" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
        <td height="5" colspan="2"><img src="../img/0.gif" width="1" height="10"></td>
        </tr>
        <tr>
        <td width="15" background="../img/bg-jdl-ppn.gif">&nbsp;</td>
        <td height="25" background="../img/bg-jdl-ppn.gif"><img src="../img/jdl-faktur-pajak-masukan.gif" height="25"></td>
        </tr>
      </table>
    </td>
  </tr><br>
 <tr>
    <td valign="top" colspan="2">
        <table class="tabelViewInside" border="0" width="98%" cellspacing="1" cellpadding="0">
          <tr>
            <td class="headerCari">
             <form action="" method="post" name="formviewspt" class="formCari">
                        <input name="txtSearch" type="text" size="20" value="<?php echo $_POST['txtSearch']; ?>" maxlength="30">
                        <font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong> Dari </strong></font>
                        <?php echo combo_tanggal('tglCari1',$tgl1,1,31)." ".combo_bulan('blnCari1',$bln1)." ".  combo_tanggal('thnCari1',$thn1,date("Y")-7,date("Y")+7)?>
                        <font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong> - </strong></font>
                        <?php echo combo_tanggal('tglCari2',$tgl2,1,31)." ".combo_bulan('blnCari2',$bln2)." ".  combo_tanggal('thnCari2',$thn2,date("Y")-7,date("Y")+7)?>
                        <input class="tombol" name="tbSearch" type="submit" value="Search" />
             </form>
            </td>
           </tr>
           <tr>
               <td><div class="scroll" style="width:<?php echo $_SESSION['wscrolldetail'];?>px;" align="center">
                  <table class="tabelIsi" width="3000" cellpadding="0" cellspacing="1">
                  <tr bgcolor="#1A75BF">
                  <th height="25">NO</th>
                  <th>WILAYAH</th>
                  <th>NO SERI F. PAJAK</th>
                  <th>TGL F. PAJAK</th>
                  <th>PROYEK</th>
                  <th>NAMA REKANAN</th>
                  <th>NPWP REKANAN</th>
                  <th>ALAMAT REKANAN</th>
                  <th>DPP</th>
                  <th>PPN(10%)</th>
<!--                  <th>N.B. PENCATATAN</th>-->
                  <th>PEMBUKUAN</th>
                  <th>N.B PEMBUKUAN</th>
                  <th>PEMBAYARAN</th>
                  <th>N.B PEMBAYARAN</th>
                  <th>LAPOR</th>
                  <th>LAPOR SPT MASA</th>
<!--                  <th>ENTRY  BY</th>
                  <th>ENTRY DATE</th>
                  <th>UPDATE BY</th>
                  <th>UPDATE DATE</th>-->
                </tr>
<?php
        $jmlppn = 0;
        $jmldpp = 0;
        $no = 0;
        $warna = '#FFFFFF';
        $sql="select a.* from tbl_spt a $cond_divisi_kode and a.no_faktur_pajak!='' ".divisi("and","divisi_kode")." $SQLtambahan order by a.tgl_faktur asc ,a.no_faktur_pajak asc";
        $result = getRSq($sql);
	while($r=pg_fetch_array($result)){
            $no++;
            if ($warna == '#FFFFFF'){
                $warna = '#E8EFFF';
            }else{
                $warna = '#FFFFFF';
            }
            if ($r['is_buku']=='N' || $r['is_bayar']=='N' || $r['is_lapor']=='N'){
                $warna = '#FF9999';
            }

            $rsL = getRS("SELECT * FROM m_leveransir WHERE id_leveransir!='' AND id_leveransir='".trim($r['id_leveransir'])."'");
            if ($rsL!=""){
                $NamaLeveransir = $rsL['nama_leveransir'];
                $NPWPLeveransir = $rsL['npwp_leveransir'];
                $AlamatLeveransir = $rsL['alamat_leveransir'];
            }
            $r['is_buku']=$r['is_buku']=="Y"?"Sudah":"Belum";
            $r['is_bayar']=$r['is_bayar']=="Y"?"Sudah":"Belum";
            $r['is_lapor']=$r['is_lapor']=="Y"?"Sudah":"Belum";
            $NamaProyek = getNameFromID("m_proyek","nama_proyek","AND id_proyek='".trim($r['id_proyek'])."'");
            $NamaDivisi = getNameFromID("tbl_divisi","divisi_name","AND divisi_kode='".trim($r['divisi_kode'])."'");
            //$rwil = getRS("SELECT divisi_name FROM tbl_divisi WHERE divisi_kode='".$r['divisi_kode']."'");
        echo "<tr bgcolor=".$warna.">
            <td class='isiGrid'>&nbsp;".$no."</td>
            <td class='isiGrid'>&nbsp;".$NamaDivisi."</td>
            <td class='isiGrid'>&nbsp;".$r['no_faktur_pajak']."</td>
            <td class='isiGrid'>&nbsp;".$r['tgl_faktur']."</td>
            <td class='isiGrid'>&nbsp;".$NamaProyek."</td>
            <td class='isiGrid'>&nbsp;".$NamaLeveransir."</td>
            <td class='isiGrid'>&nbsp;".$NPWPLeveransir."</td>
            <td class='isiGrid'>&nbsp;".$AlamatLeveransir."</td>
            <td class='isiGridNo'>".number_format($r['dpp'])."&nbsp;</td>
            <td class='isiGridNo'>".number_format($r['ppn'])."&nbsp;</td>
            <td class='isiGrid'>&nbsp;".$r['is_buku']."</td>
            <td class='isiGrid'>&nbsp;".$r['bukti_pembukuan']."</td>
            <td class='isiGrid'>&nbsp;".$r['is_bayar']."</td>
            <td class='isiGrid'>&nbsp;".$r['bukti_pembayaran']."</td>
            <td class='isiGrid'>&nbsp;".$r['is_lapor']."</td>
            <td class='isiGrid'>&nbsp;".$r['tanggal_lapor']."</td>
            <!--<td class='isiGrid'>&nbsp;".$r['entry_by']."</td>
            <td class='isiGrid'>&nbsp;".$r['entry_date']."</td>
            <td class='isiGrid'>&nbsp;".$r['update_by']."</td>
            <td class='isiGrid'>&nbsp;".$r['update_date']."</td>-->
            </tr>
            ";
        $ppn = $r['ppn'];
        $dpp = $r['dpp'];
        $jmldpp = $jmldpp + $dpp;
        $jmlppn = $jmlppn + $ppn;

}
?>
                <tr>
                    <td height="1" colspan="23" bgcolor="#6699ff"></td>
                </tr>
              </table>
                       </div>
              </td>
          </tr>
        </table>
      </td>
  </tr>
  <tr bgcolor="#FFFFFF">
      <td class="huruf8">TOTAL DPP : Rp. <?=number_format($jmldpp)?>
   </td>
  </tr>
  <tr bgcolor="#FFFFFF">
      <td class="huruf8">TOTAL PPN : Rp. <?=number_format($jmlppn)?>
   </td>
  </tr>
  <tr bgcolor="#60B0EE">
   <td class="border-nopage" align="center">
   </td>
</tr>
<tr bgcolor="#FFFFFF">
      <td align="center">
        <form name="Formbutton" class="formCari" action="#" method="">
        <input type="button" name="exit" value="Exit" class="tombol" onClick="top.window.close();">
        </form>
      </td>
  </tr>
</table>
</body>
</html>
